<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico"> 
	<link href="__PUBLIC__/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="__PUBLIC__/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="__PUBLIC__/admin/js/jquery.min.js?v=2.1.4"></script>
</head>

<script>
{if condition="(!isset($city_id)) OR (!$city_id)"}
   var url = "{:url('area/lst')}";
{else/}
   var city_id = {$city_id};
   var url = "/{$Request.module}/area/arealst/city_id/"+city_id;
{/if}
var insertUrl = "{:url('area/add')}";
var checkAreaname = "{:url('area/checkAreaname')}";
</script>

<body class="gray-bg">
<style>
input.error{
	border:1px solid red;
}
span.error{
	padding-top:10px;
	color: #f00;
	font-size:12px;
}
</style>
    <div class="wrapper wrapper-content">

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>增加区县</h5>
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal" id="form"> 
                            <div class="form-group">
                                <label class="col-sm-2 control-label">区县名称：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="area_name" class="form-control">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div> 
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">所属省份：</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b" name="pro_id">
                                        <option value="">请选择</option>
                                        {foreach name="prores" item="v"}
                                        <option value="{$v.id}" {if condition="(isset($pro_id)) AND ($v['id'] eq $pro_id)"}selected="selected"{/if}>{$v.zm}.{$v.pro_name}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div> 
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">所属城市：</label>
                                <div class="col-sm-6">
                                    <select class="form-control m-b" name="city_id" id="cityname">
                                        <option value="">请选择</option>
                                        {if condition="(isset($cityres)) AND ($cityres)"}
                                        {foreach name="cityres" item="v"}
                                        <option value="{$v.id}" {if condition="(isset($city_id)) AND ($v['id'] eq $city_id)"}selected="selected"{/if}>{$v.zm}.{$v.city_name}</option>
                                        {/foreach}
                                        {/if}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div> 
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">名称拼音首字母：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="zm" class="form-control">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>  
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">开通：</label>
                                <div class="col-sm-6">
                                        <label class="radio-inline"><input type="radio" name="checked" value="1">是</label>
                                        <label class="radio-inline"><input type="radio" name="checked" value="0">否</label>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>                        							                                                                                                        
                            
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="sort" class="form-control">
                                </div>
                                <label class="col-sm-1" style="padding-top:7px; color:#F00; font-size:16px;">*</label>
                            </div>
                            <div class="hr-line-dashed"></div>                                                                                                                                                        

                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit" id="doSubmit" style="margin-right:20px;">保存内容</button>
                                    <button type="reset" class="btn btn-default">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- 全局js -->
    <script src="__PUBLIC__/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script src="__PUBLIC__/admin/js/plugins/layer/layer.min.js"></script>
    <script src="__PUBLIC__/admin/js/plugins/validate/jquery.validate.min.js"></script>	
    <!-- iCheck -->
    <script src="__PUBLIC__/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="__PUBLIC__/admin/js/common/ajax.js"></script>      

	<script>
    	$(function(){
    		
            $('select[name=pro_id]').change(function(){
            	var pro_id = $(this).val();
            	if(pro_id != ''){
            		$.ajax({
         			   url:"{:url('area/getcitylist')}",
         			   type:'POST',
         			   data:{'pro_id':pro_id},
         		       dataType:'json',
         			   success:function(data){
         				   if(data){
                         	    var html = '';
                         	    var html='<option value="">请选择</option>';
                                $.each(data,function(i,v){
                             	   html+='<option value="'+v.id+'">'+v.zm+'.'+v.city_name+'</option>';
                             	   $('#cityname').html(html);
                                });
         				   }else{
         					   var html='<option value="">请选择</option>';
         					   $('#cityname').html(html);
         				   }
         			   }
         		    });
            	}else{
					var html='<option value="">请选择</option>';
				    $('#cityname').html(html);
            	}
            });
                                    
    	    var icon = "<i class='fa fa-times-circle'></i>&nbsp;&nbsp;";
        	$('#form').validate({
	        	errorElement : 'span',
	        	debug: true,//只验证不提交表单
	        	//layer ajax提交表单
	            submitHandler:function(){
	               // 序列化 表单数据 后提交 ，太简洁了
	            	post(insertUrl,'POST',$('#form').serialize(),1);
	                return false;
	            },//这是关键的语句，配置这个参数后表单不会自动提交，验证通过之后会去调用的方法
	                
	        	rules:{
	        		area_name:{
	        			required:true
	        		},
	        		zm:{required:true},
	        		city_id:{
	        			required:true,
	        			digits:true
	        	    },
	        		sort:{
	        			required:true,
	        			digits:true
	        	    }
	        	},
	        		
	        	messages:{
	        		area_name:{
	        			required:icon+'必填'
	        		},
	        		zm:{required:icon+'必填'},
	                city_id:{
	                	required:icon+'必选',
	                	digits:icon+'选择城市参数错误'
	                },
	                sort:{
	                	required:icon+'必填',
	                	digits:icon+'排序必须是整数'
	                }
	        	}
        	});
      });   	
    	
	  function cl(){
	     location.href = url;
	  }	  
    </script>
        

</body>
</html>
